proc pr_add_blkage { H_offset V_offset } {
    set top_size [dbget top.fPlan.coreBox]
    set top_name [dbget top.name]

    set blkage_box [dbShape ${top_size} SIZEX [expr -0.057*${H_offset}]]
    set blkage_box [dbShape ${blkage_box} SIZEY [expr -0.24*${V_offset}]]
    set box_list [dbShape ${top_size} ANDNOT ${blkage_box}]
    createPlaceBlockage -boxList ${box_list} -name ${top_name}_blkage -type hard
}

proc pr_del_blkage {} {
    set top_name [dbget top.name]
    deletePlaceBlockage ${top_name}_blkage
}

proc pr_add_routeBlkage { } {
    set row_width 0.057
    set row_heigth 0.24

    set n_row 4

    set core_box [lindex [dbget top.fPlan.coreBox] 0]
    
    set box_1 "[lindex ${core_box} 0] [lindex ${core_box} 1] [expr [lindex ${core_box} 0]+${row_width}*${n_row}] [lindex ${core_box} 3]"
    set box_2 "[expr [lindex ${core_box} 2]-${row_width}*${n_row}] [lindex ${core_box} 1] [lindex ${core_box} 2] [lindex ${core_box} 3]"
    
    createRouteBlk -box ${box_1} -layer "M0 M1 M2 M3" -name PR_ROUTEBLK_M0
    createRouteBlk -box ${box_2} -layer "M0 M1 M2 M3" -name PR_ROUTEBLK_M0
}

proc pr_delete_routeBlkage {} {
    deleteRouteBlk -name PR_ROUTEBLK_M0
}

proc pr_add_IP_RoutingBlkage {} {
    set X [expr 0.057*16]
    set Y [expr 0.24*4]
    set IPs [dbget selected]

    foreach ip ${IPs} {
        set box [dbget ${ip}.box]
        set blkage_box [dbShape ${box} SIZEX $X]
        set blkage_box [dbShape ${blkage_box} SIZEY $Y]

        createRouteBlk -box ${blkage_box} -layer "M0 M1 M2 M3 M4 M5 M6" -name PR_ROUTEBLK
    }

    set box_1 [lindex [dbget [dbget top.insts.name ILAUNCH3/NDATA_mixer -p].box] 0]
    set box_2 [lindex [dbget [dbget top.insts.name ILAUNCH0/PDATA_mixer -p].box] 0]
    
    set box "[lindex $box_1 0] [lindex $box_1 1] [lindex $box_2 2] [lindex $box_2 3]"
    puts "DOUBLE_EDGE_FF -> IP routeblkage"
    puts $box
    createRouteBlk -box ${box} -layer "M1 M2 M3 M4 M5 M6" -name PR_ROUTEBLK
}

proc pr_del_IP_RoutingBlkage {} {
    deleteRouteBlk -name PR_ROUTEBLK
}

proc pr_add_IP_PlaceBlkage {} {
    # DRC (FB.S.2.3 > 0.9)
    set X [expr 0.057*18]
    set Y [expr 0.24*4]
    set IPs [dbget selected]
    
    foreach ip ${IPs} {
        set box [dbget ${ip}.box]
        set blkage_box [dbShape ${box} SIZEX $X]
        set blkage_box [dbShape ${blkage_box} SIZEY $Y]

        createPlaceBlockage -boxList ${blkage_box} -name pr_place_blkage -type hard
    }
}

proc pr_del_IP_PlaceBlkage {} {
    deletePlaceBlockage pr_place_blkage
}

proc pr_add_coreCell_PlaceBlkage {} {
    selectInstByCellName DLY_LINE_1024_MAT
    set coreCellBox [dbget selected.box]
    createPlaceBlockage -boxList ${coreCellBox} -name pr_coreCell_blkage -type hard
    deselectAll
}

proc pr_del_coreCell_PlaceBlkage {} {
    deleteRouteBlk -name pr_coreCell_blkage
}

proc pr_add_coreCell_RouteBlkage {} {
    selectInstByCellName DLY_LINE_1024_MAT
    set coreCellBox [dbget selected.box]
    createRouteBlk -box ${coreCellBox} -name pr_coreCell_routeblkage -layer "M0 M1"
    deselectAll
}

proc pr_del_coreCell_RouteBlkage {} {
    deleteRouteBlk -name pr_coreCell_routeblkage
}

proc pr_add_PIN_RouteBlkage_route {} {
    set fpBox [dbget top.fplan.box]
    set coreBox [dbget top.fplan.coreBox]
    set coreBox [lindex [dbShape ${coreBox} SIZE 1.8 -output polygon] 0]
    set box [lindex [dbShape ${fpBox} ANDNOT ${coreBox} -output polygon] 0]
    createRouteBlk -polygon ${box} -layer "M0 M1 M2 M3 M4 M5 M6 M7 M8 M9 M10 M11" -cutLayer "VIA0 VIA1 VIA2 VIA3 VIA4 VIA5 VIA6 VIA7 VIA8 VIA9 VIA10 VIA11" -name PR_PIN_ROUTEBLK_ROUTE
}

proc pr_del_PIN_RouteBlkage_route {} {
    deleteRouteBlk -name PR_PIN_ROUTEBLK_ROUTE
}

proc pr_add_PIN_RouteBlkage_pg {} {
    set fpBox [dbget top.fplan.box]
    set coreBox [dbget top.fplan.coreBox]
    set box [lindex [dbShape ${fpBox} ANDNOT ${coreBox} -output polygon] 0]
    createRouteBlk -polygon ${box} -layer "M0 M1 M2 M3 M4 M5 M6 M7 M8 M9 M10 M11" -cutLayer "VIA0 VIA1 VIA2 VIA3 VIA4 VIA5 VIA6 VIA7 VIA8 VIA9 VIA10 VIA11" -name PR_PIN_ROUTEBLK_PG
}

proc pr_del_PIN_RouteBlkage_pg {} {
    deleteRouteBlk -name PR_PIN_ROUTEBLK_PG
}


proc pr_add_layoutRouting_RouteBlkage {} {
    set fpBox [lindex [dbget top.fplan.box] 0]

    ## right
    set box1 "[expr [lindex $fpBox 2]-8.6] [expr [lindex $fpBox 3]-4.0] [lindex $fpBox 2] [lindex $fpBox 3]"
    set box2 "[expr [lindex $fpBox 2]-4.0] [lindex $fpBox 1] [lindex $fpBox 2] [lindex $fpBox 3]"

    createRouteBlk -box $box1 -name pr_layoutRouting_RouteBlkage -layer "M8"
    createRouteBlk -box $box1 -name pr_layoutRouting_RouteBlkage -layer "M10"

    createRouteBlk -box $box2 -name pr_layoutRouting_RouteBlkage -layer "M7"
    createRouteBlk -box $box2 -name pr_layoutRouting_RouteBlkage -layer "M9"

    ## left
    set box3 "[lindex $fpBox 0] [expr [lindex $fpBox 3]-3.4] 6.4 [lindex $fpBox 3]"
    set box4 "[lindex $fpBox 0] [lindex $fpBox 1] 3.0 [lindex $fpBox 3]"

    createRouteBlk -box $box3 -name pr_layoutRouting_RouteBlkage -layer "M8"
    createRouteBlk -box $box3 -name pr_layoutRouting_RouteBlkage -layer "M10"
    createRouteBlk -box $box4 -name pr_layoutRouting_RouteBlkage -layer "M7"
    createRouteBlk -box $box4 -name pr_layoutRouting_RouteBlkage -layer "M9"

}

proc pr_add_via_RouteBlkage {} {
    set fpBox [lindex [dbget top.fplan.box] 0]
    createRouteBlk -box ${fpBox} -cutLayer "VIA3 VIA4 VIA5 VIA6 VIA7 VIA8 VIA9 VIA10 VIA11" -name PR_VIA_ROUTEBLKAGE
}

proc pr_del_via_RouteBlkage {} {
    deleteRouteBlk -name PR_VIA_ROUTEBLKAGE
}